import { Badge } from 'antd';
import type { ProColumns } from '@ant-design/pro-table';
import { crud } from './api';
import BasicForm from './form';
import BasicFormTable from '@/components/BasicFormTable';

export default () => {
  const columns: ProColumns<RegistryEntity>[] = [
    {
      title: '名称',
      dataIndex: 'name',
    },
    {
      title: '地址',
      dataIndex: 'registry',
      search: false,
    },
    {
      title: '状态',
      dataIndex: 'enable',
      hideInSearch: true,
      render: (_, record) =>
        [
          <Badge key="error" status="error" text="禁用" />,
          <Badge key="success" status="success" text="启用" />,
          <Badge key="warning" status="warning" text="不可用" />,
        ][record.enable],
    },
    {
      title: '创建时间',
      key: 'created',
      dataIndex: 'created',
      valueType: 'dateTime',
      hideInSearch: true,
    },
  ];

  return (
    <BasicFormTable<RegistryEntity>
      title={'镜像源'}
      columns={columns}
      crud={crud}
      addForm={<BasicForm />}
      updateForm={<BasicForm />}
    />
  );
};
